//
//  UIApplicationExtension.swift
//  MyTest
//
//  Created by guanzhongwang on 2021/5/12.
//

import Foundation
import UIKit

extension UIApplication{
    static let runOnce: () = {
        UITableView.awake()
        UIViewController.awake()
//        UILabel.awake()
    }()
}
protocol CustomMethodSwizzling {
    static func awake()
    static func swizzlingForClass(_ forClass:AnyClass,oldSelector:Selector,newSelector:Selector)
}
extension CustomMethodSwizzling{
    static func swizzlingForClass(_ forClass:AnyClass,oldSelector:Selector,newSelector:Selector){
        guard let oldMethod = class_getInstanceMethod(forClass, oldSelector),let newMethod = class_getInstanceMethod(forClass, newSelector) else {
            return
        }
        if class_addMethod(forClass, oldSelector, method_getImplementation(newMethod), method_getTypeEncoding(newMethod)) {
            class_replaceMethod(forClass, newSelector, method_getImplementation(oldMethod), method_getTypeEncoding(oldMethod))
        }else{
            method_exchangeImplementations(oldMethod, newMethod)
        }
    }
}
